# -*- coding: utf-8 -*-
from odoo import models, api, fields, tools
from odoo.exceptions import UserError
import re


class meteorological_month(models.Model):

    _name = "datcent.meteorological_month"
    _description = "月度数据"
    _table = "datcent_meteorological_month"
    _order = "sequence"
    _inherit =  ['mail.thread', 'mail.activity.mixin', 'image.mixin']

    sequence = fields.Integer(string="排序",translate = 0)
    name = fields.Many2one(string="站点名称",comodel_name = 'datcent.station',translate = 0)
    code = fields.Char(string="站点编码",translate = 0)
    region_id = fields.Many2one(string="省市县区",comodel_name = 'setcent.region',translate = 0)
    datetime = fields.Date(string="年月",translate = 0)
    precipitation = fields.Float(string="降雨量",translate = 0)
    min_temperature = fields.Float(string="最低气温",translate = 0)
    max_temperature = fields.Float(string="最高气温",translate = 0)
    temperature = fields.Float(string="气温",translate = 0)
    wind_speed = fields.Float(string="风速",translate = 0)
    sunshine_time = fields.Float(string="日照时数",translate = 0)
    max_wind_speed = fields.Float(string="极大风速",translate = 0)
    direction_max_wind_speed = fields.Float(string="极大风速的风向",translate = 0)
    min_pressure = fields.Float(string="最低气压",translate = 0)
    max_pressure = fields.Float(string="最高气压",translate = 0)
    pressure = fields.Float(string="气压",translate = 0)
    water_pressure = fields.Float(string="水气压",translate = 0)
    min_humidity = fields.Float(string="最小相对湿度",translate = 0)
    humidity = fields.Float(string="相对湿度",translate = 0)
    small_evaporation = fields.Float(string="小型蒸发量",translate = 0)
    state = fields.Selection(string="状态",selection = [('1', '草稿'), ('2', '提交'), ('3', '审核')],default='1',translate = 0)

    def button1(self):
        if self.state == '1':
            self.write({'state': '2'})
        # 审核
    def button2(self):
        if self.state == '2':
            self.write({'state': '3'})
        # 退回
    def button3(self):
        if self.state == '2':
            self.write({'state': '1'})

        # 反审核
    def button4(self):
        if self.state == '3':
            self.write({'state': '2'})
